package com.gmall.rabbitmq.consumer.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQServive_Fanout {

    @RabbitHandler
    @RabbitListener(queues = "Queue_Fanout_1",concurrency = "1")
    public void receive_SimpleMessage1(Channel channal, Message message,String msg){
        System.out.println("------ Queue_Fanout_1 Start-------");
        System.out.println("MessageID:"+message.getMessageProperties().getMessageId());
        System.out.println("MessageBody:"+new String(message.getBody()));
        System.out.println("msg:"+msg);
        System.out.println("------ Queue_Fanout_1 End-------");
    }

    @RabbitHandler
    @RabbitListener(queues = "Queue_Fanout_2")
    public void receive_SimpleMessage2(Channel channal, Message message,String msg){
        System.out.println("------ Queue_Fanout_2 Start-------");
        System.out.println("MessageID:"+message.getMessageProperties().getMessageId());
        System.out.println("MessageBody:"+new String(message.getBody()));
        System.out.println("msg:"+msg);
        System.out.println("------ Queue_Fanout_2 End-------");
    }

    @RabbitHandler
    @RabbitListener(queues = "Queue_Fanout_3")
    public void Queue_Direct_3(Channel channal, Message message,String msg){
        System.out.println("------ Queue_Fanout_3 Start-------");
        System.out.println("MessageID:"+message.getMessageProperties().getMessageId());
        System.out.println("MessageBody:"+new String(message.getBody()));
        System.out.println("msg:"+msg);
        System.out.println("------ Queue_Fanout_3 End-------");
    }
}
